package com.magic.smartcity.view;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.magic.smartcity.R;

/**
 * @description:
 * @create: Create by Magic on 2022/2/1.
 */
public class WelcomeActivity extends Activity {
    private static final String TAG = WelcomeActivity.class.getSimpleName();

    private final int GO_HOME = 1;
    private final int GO_WELCOME_PAGE = 2;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            switch (msg.what) {
                case GO_HOME:
                    goHome();
                    break;
                case GO_WELCOME_PAGE:
                    goWelcomePage();
                    break;

            }
        }
    };

    private void goHome() {
        startActivity(new Intent(this, MainActivity.class));
        finish();
    }

    private void goWelcomePage() {
        startActivity(new Intent(this,WelcomePageActivity.class));
        finish();
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);//全屏
        getWindow().setStatusBarColor(Color.TRANSPARENT);//状态栏透明
        setContentView(R.layout.activity_welcome);
        SharedPreferences welcome = getSharedPreferences("welcome", MODE_PRIVATE);
        boolean isFirst = welcome.getBoolean("isFirst", true);
        if (isFirst) {
            mHandler.sendEmptyMessageDelayed(GO_WELCOME_PAGE,3000);
        } else {
            mHandler.sendEmptyMessageDelayed(GO_HOME,3000);
        }


    }
}
